def is_prost(s):
    if s <= 1:
        return False
    for i in range(2, int(s**0.5) + 1):
        if s % i == 0:
            return False
    return True

def closest_prost(num):
    c = 0
    while True:
        if is_prost(num - c):
            return num - c
        elif is_prost(num + c):
            return num + c
        c += 1

list = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}

def transform(s):
    try:
        return int(''.join(str(list[word]) for word in s.split()))
    except KeyError:
        return "Wrong input"

s = input("")
num = transform(s)

if isinstance(num, int) and 100 <= num <= 999:
    print(closest_prost(num))
else:
    print("Wrong input")
